home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / s_to_z / tpack / userdos.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  5.4 KB  |  193 lines

  1. { DOS Shell and Service components by Michael Ax; Inspired by Ken Henderson}
  2.  
  3. Unit UserDOS;
  4.  
  5. interface
  6. Uses
  7.   Forms, WinTypes, Controls, Classes, WinProcs, SysUtils, Messages
  8.   , WinDos
  9. , PasUtils
  10. , UserInfo;
  11.  
  12. Type
  13.  
  14.   TDosInfo = class(TUserInfo)
  15.   {this isn't really an object and should be thought of as a function collection or
  16.   wrapper to WinDOS}
  17.   private
  18.   protected
  19.     function GetComSpec     : String; {returns environment entry}
  20.     function GetOSVersion   : String;
  21.     function GetCurrentDir  : String;
  22.     function GetPrompt      : String;
  23.     function GetPath        : String;
  24.     function GetTemp        : String;
  25.     function GetDOSDate     : String;
  26.     function GetDOSTime     : String;
  27.     function GetDiskSpace   : LongInt;
  28.     function GetFreeSpace   : LongInt;
  29.     function GetCtrlBreak   : Boolean;
  30.     function GetDOSVerify   : Boolean;
  31.     procedure SetCtrlBreak(Value:Boolean);
  32.     procedure SetDOSVerify(Value:Boolean);
  33.     procedure SetNoLongint(Value:Longint);
  34.     procedure SetDOSDate(const Value:String);
  35.     procedure SetDOSTime(const Value:String);
  36.     procedure SetCurrentDir(const Value:String);
  37.     procedure SetNoString(const Value:String);
  38.  
  39.   public
  40.     constructor Create(AOwner: TComponent); override;
  41.  
  42.   published
  43.     property CurrentDir  : String read GetCurrentDir write SetCurrentDir stored false;
  44.     property ComSpec     : String read GetComSpec write SetNoString stored false;
  45.     property Prompt      : String read GetPrompt write SetNoString stored false;
  46.     property Path        : String read GetPath write SetNoString stored false;
  47.     property Temp        : String read GetTemp write SetNoString stored false;
  48.     property OSVersion   : String read GetOSVersion write SetNoString stored false;
  49.     property DOSDate     : String read GetDOSDate write SetNoString stored false;
  50.     property DOSTime     : String read GetDOSTime write SetNoString stored false;
  51.     property DiskSpace   : Longint read GetDiskSpace write SetNoLongInt stored false;
  52.     property FreeSpace   : Longint read GetFreeSpace write SetNoLongInt stored false;
  53.     property CtrlBreak   : Boolean read GetCtrlBreak write SetCtrlBreak stored false;
  54.     property Verify      : Boolean read GetDOSVerify write SetDOSVerify stored false;
  55.   end;
  56.  
  57.  
  58. implementation
  59.  
  60. {-----------------------------------------------------------------------------------------}
  61. { TDosInfo                                                                                }
  62. {-----------------------------------------------------------------------------------------}
  63.  
  64. constructor TDosInfo.Create(AOwner: TComponent);
  65. begin
  66.   inherited Create(AOwner);
  67. end;
  68.  
  69. function TDosInfo.GetOSVersion:String;
  70. var
  71.   TempVer : word;
  72. begin
  73.   TempVer:= DosVersion;
  74.   Result:=IntToStr(Lo(TempVer))+'.'+IntToStr(Hi(TempVer));
  75. end;
  76.  
  77. function TDosInfo.GetCurrentDir:String;
  78. begin
  79.   Result:=ReceivePChar(GetCurDir(MakePChar(''),0));
  80. end;
  81.  
  82. function TDosInfo.GetComSpec: String;
  83. begin
  84.   Result:=StrPas(GetEnvVar('COMSPEC'));
  85. end;
  86.  
  87. function TDosInfo.GetPrompt:String;
  88. begin
  89.   Result:=StrPas(GetEnvVar('PROMPT'));
  90. end;
  91.  
  92. function TDosInfo.GetPath:String;
  93. begin
  94.   Result:=StrPas(GetEnvVar('PATH'));
  95. end;
  96.  
  97. function TDosInfo.GetTemp:String;
  98. begin
  99.   Result:=StrPas(GetEnvVar('TEMP'));
  100. end;
  101.  
  102. function TDosInfo.GetDiskSpace:LongInt;
  103. begin
  104.   Result:=DiskSize(0);
  105. end;
  106.  
  107. function TDosInfo.GetFreeSpace:LongInt;
  108. begin
  109.   Result:=DiskFree(0);
  110. end;
  111.  
  112. function TDosInfo.GetDOSDate:String;
  113. var
  114.   Year, Month, Day, Dow : Word;
  115. begin
  116.   GetDate(Year,Month,Day,Dow);
  117.   Result:=LeftPadZero(IntToStr(Month),2)
  118.      +'/'+LeftPadZero(IntToStr(Day),2)
  119.      +'/'+LeftPadZero(IntToStr(Year),4);
  120. end;
  121.  
  122. function TDosInfo.GetDOSTime:String;
  123. var
  124.   Hour, Minute, Second, Sec100 : Word;
  125. begin
  126.   GetTime(Hour, Minute, Second, Sec100);
  127.   Result:=LeftPadZero(IntToStr(Hour),2)+':'+LeftPadZero(IntToStr(Minute),2)+':'
  128.              +LeftPadZero(IntToStr(Second),2)+'.'+LeftPadZero(IntToStr(Sec100),2);
  129. end;
  130.  
  131. function TDosInfo.GetCtrlBreak:Boolean;
  132. begin
  133.   GetCBreak(Result);
  134. end;
  135.  
  136. function TDosInfo.GetDOSVerify:Boolean;
  137. begin
  138.   GetVerify(Result);
  139. end;
  140.  
  141. procedure TDosInfo.SetCurrentDir(const Value:String);
  142. var
  143.   Temp : array[0..255] of char;
  144. begin
  145.   SetCurDir(StrPCopy(Temp,Value));
  146. end;
  147.  
  148. procedure TDosInfo.SetDOSDate(const Value:String);
  149. var
  150.   Year, Month, Day : Word;
  151. begin
  152.   Month:=StrToInt(Copy(Value,1,2));
  153.   Day:=StrToInt(Copy(Value,4,2));
  154.   Year:=StrToInt(Copy(Value,7,4));
  155.   SetDate(Year,Month,Day);
  156. end;
  157.  
  158. procedure TDosInfo.SetDOSTime(const Value:String);
  159. var
  160.   Hour, Minute, Second, Sec100 : Word;
  161. begin
  162.   Hour:=StrToInt(Copy(Value,1,2));
  163.   Minute:=StrToInt(Copy(Value,4,2));
  164.   Second:=StrToInt(Copy(Value,7,2));
  165.   Sec100:=StrToIntDef(Copy(Value,10,2),0);
  166.   SetTime(Hour,Minute,Second, Sec100);
  167. end;
  168.  
  169. procedure TDosInfo.SetCtrlBreak(Value:Boolean);
  170. begin
  171.   SetCBreak(Value);
  172. end;
  173.  
  174. procedure TDosInfo.SetDOSVerify(Value:Boolean);
  175. begin
  176.   SetVerify(Value);
  177. end;
  178.  
  179. procedure TDosInfo.SetNoString(const Value:String);
  180. begin
  181. end;
  182.  
  183. procedure TDosInfo.SetNoLongint(Value:Longint);
  184. begin
  185. end;
  186.  
  187. {-----------------------------------------------------------------------------------------}
  188. {                                                                                         }
  189. {-----------------------------------------------------------------------------------------}
  190.  
  191. end.
  192.  
  193.